import { Db } from "../common"

export async function is_friend(userid:string,friendid:string){
  
    //是否已经是好友
    let f_list = (await Db()).collection("friend_list").find({
      $or: [
          {
            userid: userid,
            state:1
          },
          {
            friend_userid: userid,
            state:1
          }
      ],
    })
    let isfriend=false
    await f_list.forEach((doc) => {
      let friend_id = ''
      if (doc.userid == userid) {
        friend_id=doc.friend_userid
      } else {
        friend_id=doc.userid
      }
      if (friend_id == friendid) {
        isfriend=true
      }
    })
    return isfriend
  
  }
  